<?php
namespace Home\Controller;


class YgController extends HomeController {
    
    public function index(){
        //根据session查名字(右上角显示)
       $name1 = $this->name1;
       
       //根据session查上次登录时间
       $un1 = $_SESSION['user']['name'];
       $lt  = M('userdetail')->field('lastlogin')->where(array("uname"=>"$un1"))->find();

       //显示公告
       $list = M('notice')->field('id,ntitle,ncontent')->select();

       //天气接口
       $ch = curl_init();
       $word = urlencode('上海');
        $url = 'http://apis.baidu.com/apistore/weatherservice/cityname?cityname='.$word;
        $header = array(
          'apikey: 2d89d4374453023c4864afb12b6a115d',
        );
       // 添加apikey到header
      curl_setopt($ch, CURLOPT_HTTPHEADER  , $header);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      // 执行HTTP请求
       curl_setopt($ch , CURLOPT_URL , $url);
      $res = curl_exec($ch);
      $obj = json_decode($res);
      //var_dump(json_decode($res));exit;
      $tianqi = $obj->retData->weather;
      $l_tmp = $obj->retData-> l_tmp;
      $h_tmp = $obj->retData->h_tmp;
      $_SESSION['weather']['tianqi'] = $tianqi;
      $_SESSION['weather']['l_tmp'] = $l_tmp;
      $_SESSION['weather']['h_tmp'] = $h_tmp;
      
       
       $this->assign('name1',$name1['name']);
       $this->assign('lastlogin',$lt['lastlogin']);
       /*$this->assign('tianqi',$tianqi);
       $this->assign('l_tmp',$l_tmp);
       $this->assign('h_tmp',$h_tmp);*/
       $this->assign('list',$list);
       

       $this->display();
    }

 
}